import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

/*** class in charge of menu ***/
public class GuiMenu {
	
	private final Shell shell;
	private Menu menu;
	private MenuItem fileItem, boxItem;
	private GuiCommands gCmnds;
	
	//c'tor receives shell and commands class
	public GuiMenu(final Shell shell, GuiCommands gCmnds){
		this.shell = shell;
		this.gCmnds = gCmnds;
		//initialize menu bar
		menu = new Menu(shell, SWT.BAR); 
	 	//set menu items
		fileItem = new MenuItem(menu, SWT.CASCADE);
	 	fileItem.setText("File");
	 	setFileMenu();
	 	
	    boxItem = new MenuItem(menu, SWT.CASCADE);
	    boxItem.setText("Box");
	    setBoxMenu();
		    
		shell.setMenuBar(menu);
		
		
		   
	}
	
	//method sets file menu
	private void setFileMenu(){
	    Menu fileMenu = new Menu(menu);
	    fileItem.setMenu(fileMenu);
	    
	    //set texts
	    MenuItem startSimItem = new MenuItem(fileMenu, SWT.NONE);
	    startSimItem.setText("Start Simulation");
	    MenuItem stopSimItem = new MenuItem(fileMenu, SWT.NONE);
	    stopSimItem.setText("Stop Simulation");
	    
	    new MenuItem(fileMenu, SWT.SEPARATOR); //line separator
	    MenuItem exitItem = new MenuItem(fileMenu, SWT.NONE);
	    exitItem.setText("Exit");
	    
	    
	    //start simulation listener
	    startSimItem.addSelectionListener(new SelectionAdapter(){
	    	public void widgetSelected(SelectionEvent event) {
	    		  gCmnds.simulate();
	    	}
	    });
	    
	  //start simulation listener
	    stopSimItem.addSelectionListener(new SelectionAdapter(){
	    	public void widgetSelected(SelectionEvent event) {
	    		  GUI.stopSim();
	    	}
	    });
	    
	    //exit listener
	    exitItem.addSelectionListener(new SelectionAdapter(){
	    	public void widgetSelected(SelectionEvent event) {
	    		  //close shell when exit is called
			      shell.close();
	    	}
	    });
	}
	
	//method sets box menu
	private void setBoxMenu(){
		 //box menu
	    Menu boxMenu = new Menu(menu);
	    boxItem.setMenu(boxMenu);
	    
	    MenuItem AddBoxItem = new MenuItem(boxMenu, SWT.NONE);
	    AddBoxItem.setText("Add Box");
	
	
		//Add Box listener
		AddBoxItem.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent event) {
				gCmnds.addBox();
				
			}
		});
	}
	  
}

